<template>
  <div class="login-container">
    <!-- 登录页面头部 -->
    <div class="navbar">
      <div class="left-menu">
        <img src="./../../assets/images/layout/logo.png" alt="">
        <div>污染源自动监控设施第三方运维信息管理系统</div>
      </div>
    </div>
    <!-- 登录页内容框 -->
    <div class="body">
      <div class="loginbg">
        <!-- 登录框 -->
        <div class="login">
          <div class="loginbox">
            <el-form
              ref="loginForm"
              :model="loginForm"
              :rules="loginRules"
              class="login-form"
              auto-complete="on"
              label-position="left"
            >
              <div class="title-container">
                <h3 class="title">登 录</h3>
              </div>
              <div class="heng">
                <img src="../../assets/images/layout/hengxian.png">
              </div>
              <el-form-item prop="username">
                <span class="svg-container">
                  <img src="../../assets/images/layout/user.png">
                </span>
                <el-input
                  ref="username"
                  v-model="loginForm.username"
                  placeholder="请输入用户名"
                  name="username"
                  type="text"
                  tabindex="1"
                  auto-complete="on"
                />
              </el-form-item>

              <el-form-item prop="password">
                <span class="svg-container">
                  <img src="../../assets/images/layout/password.png">
                </span>
                <el-input
                  :key="passwordType"
                  ref="password"
                  v-model="loginForm.password"
                  :type="passwordType"
                  placeholder="请输入密码"
                  name="password"
                  tabindex="2"
                  auto-complete="on"
                  @keyup.enter.native="handleLogin"
                />
                <span class="show-pwd" @click="showPwd">
                  <svg-icon
                    :icon-class="
                      passwordType === 'password' ? 'eye' : 'eye-open'
                    "
                  />
                </span>
              </el-form-item>
              <div class="remember">
                <template>
                  <el-checkbox
                    v-model="checked"
                    class="rememberps"
                  >记住密码</el-checkbox>
                </template>
              </div>

              <div class="button1">
                <el-button
                  :loading="loading"
                  type="primary"
                  class="button"
                  @click.native.prevent="handleLogin"
                >
                  登录
                </el-button>
              </div>
            </el-form>
          </div>
        </div>
        <div class="tips">
          <p>公司名称：成都乐攀环保科技有限公司</p>
          <p>地址：成都市锦江区金石路366号中鼎国际2栋10层3-4号</p>
          <p>电话：400 6010 209</p>
          <p>技术支持电话：18011528851</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Login',
  data() {
    return {
      checked: true,
      loginForm: {
        username: '',
        password: ''
      },
      loginRules: {
        username: [
          {
            required: true,
            trigger: 'blur',
            message: '请输入用户名'
          }
        ],
        password: [
          {
            required: true,
            trigger: 'blur',
            message: '请输入密码'
          }
        ]
      },
      loading: false,
      passwordType: 'password',
      redirect: undefined
    }
  },
  watch: {
    $route: {
      handler: function(route) {
        // this.redirect = route.query && route.query.redirect
        this.redirect = undefined
      },
      immediate: true
    }
  },
  methods: {
    showPwd() {
      if (this.passwordType === 'password') {
        this.passwordType = ''
      } else {
        this.passwordType = 'password'
      }
      this.$nextTick(() => {
        this.$refs.password.focus()
      })
    },
    handleLogin() {
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          this.loading = true
          this.$store
            .dispatch('user/login', this.loginForm)
            .then((res) => {
              // console.log(res)
              this.loading = false
              if (res.success) {
                this.$router.push({
                  path: this.redirect || '/'
                })
              } else {
                this.$message.error(res.message)
              }
            })
            .catch((error) => {
              // console.log(error)
              this.$message.error(error)
              this.loading = false
            })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
</script>

<style lang="scss">
/* 修复input 背景不协调 和光标变色 */
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */

$bg: #283443;
$light_gray: #fff;
$cursor: #fff;

@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  .login-container .el-input input {
    color: $cursor;
  }
}

.login-container {
  .navbar {
    height: 60px;
    left: 0;
    top: 0;
    overflow: hidden;
    background: #f8f9fd;
    // box-shadow: 0 1px 4px rgba(0,21,41,.08);
    background: url("./../../assets/images/layout/header_bg.png");
    background-size: 105% 110%;
  }

  .button1 {
    width: 413px;
    text-align: center;
  }

  .button {
    width: 371px;
    height: 54px;
    font-size: 22px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #ffffff;
    border-radius: 0px;
  }

  .left-menu {
    float: left;
    height: 59px;
    display: flex;
    align-items: center;
    padding-left: 50px;

    img {
      width: 60px;
      height: 45px;
    }

    div {
      padding-left: 24px;
      color: #fff;
      font-size: 26px;
    }
  }

  .body {
    // width: 1918px;
    margin: 0 auto;
    height: 85%;
        background: url(../../assets/images/layout/loginbackground.png) no-repeat;
    background-size: 100%;
  }

  .loginbg {
padding-top: 100px;
    // width: 1604px;
    // height: 890px;
  }

  .login {
    width: 633px;
    // height: 470px;
    margin: 0 auto;
  }

  .el-input {
    display: inline-block;
    height: 47px;
    width: 85%;

    input {
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 15px 12px 0px;
      caret-color: $cursor;

      height: 54px;
      font-size: 22px;
      font-family: Source Han Sans CN;
      font-weight: 400;
      color: #156dac;

      &:-webkit-autofill {
        box-shadow: 0 0 0px 1000px $bg inset !important;
        -webkit-text-fill-color: $cursor !important;
      }
    }
  }

  .el-form-item {
    width: 371px;
    height: 54px;
    background: #ffffff;
    border: 1px solid #dcdcdc;
    border-radius: 9px;
    margin: 25px auto;
  }

  #verification {
    width: 225px;
    height: 54px;
    margin: 0 0 15px 20px;
    text-align: center;
  }

  #input1 {
    padding: 0;
    text-align: center;
  }
}

@media screen and (max-width: 1550px) {
.login-container {
  .navbar {
    height: 60px;
    left: 0;
    top: 0;
    overflow: hidden;
    background: #f8f9fd;
    // box-shadow: 0 1px 4px rgba(0,21,41,.08);
    background: url("./../../assets/images/layout/header_bg.png");
    background-size: 105% 110%;
  }

  .button1 {
    width: 413px;
    text-align: center;
  }

  .button {
    width: 371px;
    height: 54px;
    font-size: 22px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #ffffff;
    border-radius: 0px;
  }

  .left-menu {
    float: left;
    height: 59px;
    display: flex;
    align-items: center;
    padding-left: 20px;

    img {
      width: 60px;
      height: 45px;
    }

    div {
      padding-left: 14px;
      color: #fff;
      font-size: 26px;
    }
  }

  .body {
    background: url(../../assets/images/layout/loginbackground.png) no-repeat;
    background-size: 100%;
    height: 80%;
  }

  .loginbg {
  padding-top: 5%;
    // width: 1604px;
    // height: 890px;
  }

  .login {
    width: 450px;
    // height: 470px;
    margin: 0 auto;
  }

  .el-input {
    display: inline-block;
    height: 47px;
    width: 85%;

    input {
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 15px 12px 0px;
      caret-color: $cursor;

      height: 54px;
      font-size: 22px;
      font-family: Source Han Sans CN;
      font-weight: 400;
      color: #156dac;

      &:-webkit-autofill {
        box-shadow: 0 0 0px 1000px $bg inset !important;
        -webkit-text-fill-color: $cursor !important;
      }
    }
  }

  .el-form-item {
    width: 371px;
    height: 54px;
    background: #ffffff;
    border: 1px solid #dcdcdc;
    border-radius: 9px;
    margin: 25px auto;
  }

  #verification {
    width: 225px;
    height: 54px;
    margin: 0 0 15px 20px;
    text-align: center;
  }

  #input1 {
    padding: 0;
    text-align: center;
  }
}
}
</style>

<style lang="scss" scoped>
$bg: #2d3a4b;
$dark_gray: #889aa4;
$light_gray: #eee;

.login-container {
  width: 100%;
  height: 100%;
  background: #ffffff;

  .login-form {
    width: 485px;
    height: 549px;
    margin: 0 auto;
    padding: 36px;
    padding-top: 70px;
  }

  .heng {
    width: 413px;
    text-align: center;
    margin-bottom: 46px;
  }

  .loginbox {
    background-color: white;
       box-shadow: 0px 0px 34px -3px #8886a7;
    width: 633px;
    // height: 693px;
    background-position: center center;

  }

  .tips {
    font-size: 14px;
    color: #001528;
    // margin-top: 310px;
    text-align: center;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;

    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }

  .remember {
    width: 389px;
    height: 21px;
    text-align: right;
    margin: 25px 0 35px 0;
  }

  .rememberps {
    width: 86px;
    height: 21px;
    font-size: 22px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #000000;
  }

  .svg-container {
    margin: 3px 5px 3px 17px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }

  .title-container {
    position: relative;

    .title {
      width: 72px;
      height: 28px;
      font-size: 30px;
      font-family: Source Han Sans CN;
      font-weight: 400;
      color: #1b1b1b;
      margin: 0px auto;
      text-align: center;
    }
  }

  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }
}

@media screen and (max-width: 1550px) {
.login-container {
  width: 100%;
  height: 100%;
  background: #ffffff;

  .login-form {
    width: 450px;
    height: 549px;
    height: 360px;
    margin: 0 auto;
    padding: 15px;
  }

  .heng {
    width: 413px;
    text-align: center;
    margin-bottom: 23px;
  }

  .loginbox {
       box-shadow: 0px 0px 34px -3px #8886a7;
    width: 450px;
    // height: 693px;
    background-position: center center;

  }

  .tips {
    font-size: 14px;
    color: #001528;
    // margin-top: 310px;
    text-align: center;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;

    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
    p{
      margin-top: 5px;
      margin-bottom: 5px;
    }
  }

  .remember {
    width: 389px;
    height: 21px;
    text-align: right;
    margin: 12px 0 16px 0;
  }

  .rememberps {
    width: 86px;
    height: 21px;
    font-size: 22px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #000000;
  }

  .svg-container {
    margin: 3px 5px 3px 17px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }

  .title-container {
    position: relative;

    .title {
      width: 72px;
      height: 28px;
      font-size: 30px;
      font-family: Source Han Sans CN;
      font-weight: 400;
      color: #1b1b1b;
      margin: 0px auto;
      text-align: center;
    }
  }

  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }
}
}
</style>
